package com.example.administrator.caigou51.widget.EditDialog;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import android.app.Dialog;
import android.content.Context;
import android.content.res.AssetManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ab.util.AbViewUtil;
import com.example.administrator.caigou51.R;

import de.greenrobot.event.EventBus;

public class EditDialog extends Dialog {
	public static Context context;
    
    
	public EditDialog(Context context, int theme) {
		super(context, theme);

	}


	public static EditDialog create(Context context, String[] items,
			final EditDialogAction action) {
		final EditDialog dialog = new EditDialog(context,
				R.style.style_share_dialog);
		dialog.getWindow().setWindowAnimations(R.style.dialogWindowAnim);
		LayoutInflater inflater = LayoutInflater.from(context);

		View contentView = inflater.inflate(R.layout.template_editdialog, null);

		TextView tv_item1 = (TextView) contentView.findViewById(R.id.tv_item1);
		TextView tv_item2 = (TextView) contentView.findViewById(R.id.tv_item2);
		TextView tv_item3 = (TextView) contentView.findViewById(R.id.tv_item3);
		TextView tv_item4 = (TextView) contentView.findViewById(R.id.tv_item4);

		tv_item1.setVisibility(View.GONE);
		tv_item2.setVisibility(View.GONE);
		tv_item3.setVisibility(View.GONE);
		tv_item4.setVisibility(View.GONE);

		TextView tv_cancel = (TextView) contentView
				.findViewById(R.id.tv_cancel);

		List<TextView> tvList = new ArrayList<TextView>();
		tvList.add(tv_item1);
		tvList.add(tv_item2);
		tvList.add(tv_item3);
		tvList.add(tv_item4);

		for (int i = 0; i < items.length; i++) {
			tvList.get(i).setText(items[i]);
			if(items[i].equals("解散部落")){
				tvList.get(i).setTextColor(context.getResources().getColor(R.color.red));
			}
			tvList.get(i).setVisibility(View.VISIBLE);
		}

		dialog.setContentView(contentView);
		dialog.setCanceledOnTouchOutside(false);

		contentView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (dialog.isShowing()) {
					dialog.dismiss();
				}
				return false;
			}
		});

		tv_item1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				action.clickItem1();
				dialog.dismiss();
			}
		});
		tv_item2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				action.clickItem2();
				dialog.dismiss();
			}
		});
		tv_item3.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				action.clickItem3();
				dialog.dismiss();
			}
		});
		tv_item4.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				action.clickItem4();
				dialog.dismiss();
			}
		});
		tv_cancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();

			}
		});
		return dialog;
	}



	
	
}
